<?php

namespace Cmd\user;

use EasyWeChat\Kernel\Messages\News;
use EasyWeChat\Kernel\Messages\NewsItem;
use Instagram\instagram as Ins;

class instagram
{
    /**
     * instagram命令入口
     *
     * @param [type] $message
     * @return void
     */
    public function instagram($message)
    {
        return '由于Instagram不再允许匿名用户查看照片/视频，此命令暂时无法正常工作。一个新版本正在开发中，感谢您的支持。';
        if (mb_substr($message, 0, '28') != 'https://www.instagram.com/p/' && mb_substr($message, 0, '24') != 'https://instagram.com/p/') {
            return "链接地址需以\nhttps://www.instagram.com/p/\nhttps://instagram.com/p/\n开头 <a href='https://mp.weixin.qq.com/s/rxNJhOyZTpdddILUs9EIfA'>查看帮助</a>";
        }
        $url = str_replace(array('https://www.instagram.com/', 'https://instagram.com/'), '', $message);
        $result = (new Ins)->data($url);
        if ($result['code'] == 400) {
            return $result['msg'];
        }
        switch ($result['data']['info']['type']) {
            case 'video':
                $tips = '视频';
                break;
            case 'images':
                $tips = '所有照片';
                break;
            default:
                $tips = '照片';
                break;
        }
        return new News([
            new NewsItem([
                'title'       => '需VPN | @' . $result['data']['owner']['username'] . ' 的 Instagram ' . $tips,
                'description' => '查看图片，长按可保存到手机相册',
                'url'         => request()->domain() . '/instagram/index?data=' . urlencode(json_encode($result['data'])),
                'image'       => $result['data']['info']['thumb']
            ])
        ]);
    }
}
